home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_5 / tpcoeff.m < prev   
Encoding:
Text File  |  1994-06-05  |  544 b   |  24 lines  |  [MATF/MATL]

  1. function [A,B] = tpcoeff(X,Y,m)
  2. % [A,B] = tpcoeff(X,Y,m)
  3. % X vector of equally spaced abscissax in [-pi,pi], input.
  4. % Y vector of ordinates, input.
  5. % m degree of the trigonomitric polynomial, input.
  6. % A coefficients of cos(nx), output.
  7. % B coefficients of sin(nx), output.
  8. n = length(X)-1;
  9. max1 = fix((n-1)/2);
  10. if m>max1, m=max1; end
  11. A = zeros(1,m+1);
  12. B = zeros(1,m+1);
  13. Yends = (Y(1)+Y(n+1))/2;
  14. Y(1)   = Yends;
  15. Y(n+1) = Yends;
  16. A(1) = sum(Y);
  17. for j = 1:m,
  18.   A(j+1) = cos(j*X)*Y';
  19.   B(j+1) = sin(j*X)*Y';
  20. end
  21. A = 2*A/n;
  22. B = 2*B/n;
  23. A(1) = A(1)/2;
  24.